package com.hsnn.medstgmini.pro.base.controller;


import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hsnn.medstgmini.Constants;
import com.hsnn.medstgmini.base.dict.service.DicAreaManager;
import com.hsnn.medstgmini.base.std.model.StdCompinfo;
import com.hsnn.medstgmini.pro.base.service.PsAnaDruginfoManager;
import com.hsnn.medstgmini.sys.model.SysUser;
import com.hsnn.medstgmini.util.DbUtil;
import com.hsnn.medstgmini.util.Pagination;

/**
 * @category 统计与查询
 * @author wangbing
 * @date 2015年12月1日10:16:59
 */
@Controller
@RequestMapping("/psAnaDruginfo")
public class PsAnaDruginfoController {

	private static final Logger log = Logger.getLogger(PsAnaDruginfoController.class);
	@Autowired
	private  PsAnaDruginfoManager psAnaDruginfoManager;
	
	@Autowired
	private HttpServletRequest request;

	@Autowired
	private HttpSession session;
	@Value("#{sysProp['system.province']}")
    private String sysProvince;
	@Autowired
	private DicAreaManager dicAreaManager;
	
	/**
	 * @category 按地区统计(月)
	 * @date 2015年12月1日10:18:44
	 * @return
	 */
	@RequestMapping("/toPsMonthAnaByArea")
	public String toPsMonthAnaByArea() {
		request.setAttribute("province", sysProvince);
		Map<String, Object> area = dicAreaManager.getAreaByAreaId(sysProvince);
		request.setAttribute("provinceName", area.get("area_name"));
		return "/pro/base/anaDruginfo/psMonthAnaByArea";
	}
	@ResponseBody
	@RequestMapping("/getPsMonthAnaByArea")
	public Pagination getPsMonthAnaByArea() {
		Pagination page = new Pagination(request);
		try {
			SysUser user = (SysUser) session.getAttribute(Constants.USERINFO);
			StdCompinfo compinfo = user.getInfo();
			page.getConditions().put("compCode", compinfo.getCompCode());
			DbUtil.jsonToMap(request, page);
			
			page = psAnaDruginfoManager.getPsMonthAnaByArea(page);
			page.setSuccess(true);
		} catch (Exception e) {
			log.error("",e);
			page.setSuccess(false);
		}
		return page;
	}
	
	/**
	 * @category 按地区统计(年)
	 * @date 2015年12月1日10:18:44
	 * @return
	 */
	@RequestMapping("/toPsYearAnaByArea")
	public String toPsYearAnaByArea() {
		request.setAttribute("province", sysProvince);
		Map<String, Object> area = dicAreaManager.getAreaByAreaId(sysProvince);
		request.setAttribute("provinceName", area.get("area_name"));
		return "/pro/base/anaDruginfo/psYearAnaByArea";
	}
	@ResponseBody
	@RequestMapping("/getPsYearAnaByArea")
	public Pagination getPsYearAnaByArea() {
		Pagination page = new Pagination(request);
		try {
			SysUser user = (SysUser) session.getAttribute(Constants.USERINFO);
			StdCompinfo compinfo = user.getInfo();
			page.getConditions().put("compCode", compinfo.getCompCode());
			DbUtil.jsonToMap(request, page);
			
			page = psAnaDruginfoManager.getPsYearAnaByArea(page);
			page.setSuccess(true);
		} catch (Exception e) {
			log.error("",e);
			page.setSuccess(false);
		}
		return page;
	}
	
	/**
	 * @category 按地区统计(日)
	 * @date 2015年12月1日10:18:44
	 * @return
	 */
	@RequestMapping("/toPsAnaByArea")
	public String toPsAnaByArea() {
		request.setAttribute("province", sysProvince);
		Map<String, Object> area = dicAreaManager.getAreaByAreaId(sysProvince);
		request.setAttribute("provinceName", area.get("area_name"));
		return "/pro/base/anaDruginfo/psAnaByArea";
	}
	@ResponseBody
	@RequestMapping("/getPsAnaByArea")
	public Pagination getPsAnaByArea() {
		Pagination page = new Pagination(request);
		try {
			SysUser user = (SysUser) session.getAttribute(Constants.USERINFO);
			StdCompinfo compinfo = user.getInfo();
			page.getConditions().put("compCode", compinfo.getCompCode());
			DbUtil.jsonToMap(request, page);
			
			page = psAnaDruginfoManager.getPsAnaByArea(page);
			page.setSuccess(true);
		} catch (Exception e) {
			log.error("",e);
			page.setSuccess(false);
		}
		return page;
	}
	
	/**
	 * @category 按地区统计(季度)
	 * @date 2015年12月1日10:18:44
	 * @return
	 */
	@RequestMapping("/toPsSeaAnaByArea")
	public String toPsSeaAnaByArea() {
		request.setAttribute("province", sysProvince);
		Map<String, Object> area = dicAreaManager.getAreaByAreaId(sysProvince);
		request.setAttribute("provinceName", area.get("area_name"));
		return "/pro/base/anaDruginfo/psSeaAnaByArea";
	}
	@ResponseBody
	@RequestMapping("/getPsSeaAnaByArea")
	public Pagination getPsSeaAnaByArea() {
		Pagination page = new Pagination(request);
		try {
			SysUser user = (SysUser) session.getAttribute(Constants.USERINFO);
			StdCompinfo compinfo = user.getInfo();
			page.getConditions().put("compCode", compinfo.getCompCode());
			DbUtil.jsonToMap(request, page);
			
			page = psAnaDruginfoManager.getPsSeaAnaByArea(page);
			page.setSuccess(true);
		} catch (Exception e) {
			log.error("",e);
			page.setSuccess(false);
		}
		return page;
	}
	
	
	/*-----------------------------------------------按时间查询----------------------------------------------------------*/
	/**
	 * @category 按时间统计(月)
	 * @date 2015年12月1日10:18:44
	 * @return
	 */
	@RequestMapping("/toPsMonthAnaByTime")
	public String toPsMonthAnaByTime() {
		return "/pro/base/anaDruginfo/psMonthAnaByTime";
	}
	@ResponseBody
	@RequestMapping("/getPsMonthAnaByTime")
	public Pagination getPsMonthAnaByTime() {
		Pagination page = new Pagination(request);
		try {
			SysUser user = (SysUser) session.getAttribute(Constants.USERINFO);
			StdCompinfo compinfo = user.getInfo();
			page.getConditions().put("compCode", compinfo.getCompCode());
			DbUtil.jsonToMap(request, page);
			
			page = psAnaDruginfoManager.getPsMonthAnaByTime(page);
			page.setSuccess(true);
		} catch (Exception e) {
			log.error("",e);
			page.setSuccess(false);
		}
		return page;
	}
	
	/**
	 * @category 按时间统计(年)
	 * @date 2015年12月1日10:18:44
	 * @return
	 */
	@RequestMapping("/toPsYearAnaByTime")
	public String toPsYearAnaByTime() {
		return "/pro/base/anaDruginfo/psYearAnaByTime";
	}
	@ResponseBody
	@RequestMapping("/getPsYearAnaByTime")
	public Pagination getPsYearAnaByTime() {
		Pagination page = new Pagination(request);
		try {
			SysUser user = (SysUser) session.getAttribute(Constants.USERINFO);
			StdCompinfo compinfo = user.getInfo();
			page.getConditions().put("compCode", compinfo.getCompCode());
			DbUtil.jsonToMap(request, page);
			
			page = psAnaDruginfoManager.getPsYearAnaByTime(page);
			page.setSuccess(true);
		} catch (Exception e) {
			log.error("",e);
			page.setSuccess(false);
		}
		return page;
	}
	
	/**
	 * @category 按时间统计(日)
	 * @date 2015年12月1日10:18:44
	 * @return
	 */
	@RequestMapping("/toPsAnaByTime")
	public String toPsAnaByTime() {
		return "/pro/base/anaDruginfo/psAnaByTime";
	}
	@ResponseBody
	@RequestMapping("/getPsAnaByTime")
	public Pagination getPsAnaByTime() {
		Pagination page = new Pagination(request);
		try {
			SysUser user = (SysUser) session.getAttribute(Constants.USERINFO);
			StdCompinfo compinfo = user.getInfo();
			page.getConditions().put("compCode", compinfo.getCompCode());
			DbUtil.jsonToMap(request, page);
			
			page = psAnaDruginfoManager.getPsAnaByTime(page);
			page.setSuccess(true);
		} catch (Exception e) {
			log.error("",e);
			page.setSuccess(false);
		}
		return page;
	}
	
	/**
	 * @category 按时间统计(季度)
	 * @date 2015年12月1日10:18:44
	 * @return
	 */
	@RequestMapping("/toPsSeaAnaByTime")
	public String toPsSeaAnaByTime() {
		return "/pro/base/anaDruginfo/psSeaAnaByTime";
	}
	@ResponseBody
	@RequestMapping("/getPsSeaAnaByTime")
	public Pagination getPsSeaAnaByTime() {
		Pagination page = new Pagination(request);
		try {
			SysUser user = (SysUser) session.getAttribute(Constants.USERINFO);
			StdCompinfo compinfo = user.getInfo();
			page.getConditions().put("compCode", compinfo.getCompCode());
			DbUtil.jsonToMap(request, page);
			
			page = psAnaDruginfoManager.getPsSeaAnaByTime(page);
			page.setSuccess(true);
		} catch (Exception e) {
			log.error("",e);
			page.setSuccess(false);
		}
		return page;
	}
}
